#include "regexp.h"
#include "debug.h"

const int kMaxArgs = 16;

bool RE::PartialMatch(const TCHAR* text, const RE& re,  // 3..16 args
					  CString * a0,
					  CString * a1,
					  CString * a2,
					  CString * a3,
					  CString * a4,
					  CString * a5,
					  CString * a6,
					  CString * a7,
					  CString * a8,
					  CString * a9,
					  CString * a10,
					  CString * a11,
					  CString * a12,
					  CString * a13,
					  CString * a14,
					  CString * a15)
{
	ASSERT(text, (L""));
	// a0 may be NULL
	// a1 may be NULL
	// a2 may be NULL
	// a3 may be NULL
	// a4 may be NULL
	// a5 may be NULL
	// a6 may be NULL
	// a7 may be NULL
	// a8 may be NULL
	// a9 may be NULL
	// a10 may be NULL
	// a11 may be NULL
	// a12 may be NULL
	// a13 may be NULL
	// a14 may be NULL
	// a15 may be NULL

	CString * args[kMaxArgs];
	int n = 0;
	if (a0 == NULL) goto done; args[n++] = a0;
	if (a1 == NULL) goto done; args[n++] = a1;
	if (a2 == NULL) goto done; args[n++] = a2;
	if (a3 == NULL) goto done; args[n++] = a3;
	if (a4 == NULL) goto done; args[n++] = a4;
	if (a5 == NULL) goto done; args[n++] = a5;
	if (a6 == NULL) goto done; args[n++] = a6;
	if (a7 == NULL) goto done; args[n++] = a7;
	if (a8 == NULL) goto done; args[n++] = a8;
	if (a9 == NULL) goto done; args[n++] = a9;
	if (a10 == NULL) goto done; args[n++] = a10;
	if (a11 == NULL) goto done; args[n++] = a11;
	if (a12 == NULL) goto done; args[n++] = a12;
	if (a13 == NULL) goto done; args[n++] = a13;
	if (a14 == NULL) goto done; args[n++] = a14;
	if (a15 == NULL) goto done; args[n++] = a15;

done:
	return re.DoMatchImpl(text, args, n, NULL);
}

// Like PartialMatch(), except the "input" is advanced past the matched
// text.  Note: "input" is modified iff this routine returns true.
// For example, "FindAndConsume(s, "(\\w+)", &word)" finds the next
// word in "s" and stores it in "word".
bool RE::FindAndConsume(const TCHAR **input, const RE& re,
						CString * a0,
						CString * a1,
						CString * a2,
						CString * a3,
						CString * a4,
						CString * a5,
						CString * a6,
						CString * a7,
						CString * a8,
						CString * a9,
						CString * a10,
						CString * a11,
						CString * a12,
						CString * a13,
						CString * a14,
						CString * a15)
{
	ASSERT(input, (L""));
	// a0 may be NULL
	// a1 may be NULL
	// a2 may be NULL
	// a3 may be NULL
	// a4 may be NULL
	// a5 may be NULL
	// a6 may be NULL
	// a7 may be NULL
	// a8 may be NULL
	// a9 may be NULL
	// a10 may be NULL
	// a11 may be NULL
	// a12 may be NULL
	// a13 may be NULL
	// a14 may be NULL
	// a15 may be NULL

	CString * args[kMaxArgs];
	int n = 0;
	if (a0 == NULL) goto done; args[n++] = a0;
	if (a1 == NULL) goto done; args[n++] = a1;
	if (a2 == NULL) goto done; args[n++] = a2;
	if (a3 == NULL) goto done; args[n++] = a3;
	if (a4 == NULL) goto done; args[n++] = a4;
	if (a5 == NULL) goto done; args[n++] = a5;
	if (a6 == NULL) goto done; args[n++] = a6;
	if (a7 == NULL) goto done; args[n++] = a7;
	if (a8 == NULL) goto done; args[n++] = a8;
	if (a9 == NULL) goto done; args[n++] = a9;
	if (a10 == NULL) goto done; args[n++] = a10;
	if (a11 == NULL) goto done; args[n++] = a11;
	if (a12 == NULL) goto done; args[n++] = a12;
	if (a13 == NULL) goto done; args[n++] = a13;
	if (a14 == NULL) goto done; args[n++] = a14;
	if (a15 == NULL) goto done; args[n++] = a15;

done:
	return re.DoMatchImpl(*input,args,n,input);
}